//
//  HomeViewController.m
//  StarOrangeStaff
//
//  Created by lshenrong on 2020/6/22.
//  Copyright © 2020 lshenrong. All rights reserved.
//

#import "HomeViewController.h"
#import "InfoManageController.h"
#import "ClientListController.h"
#import "ClientAddController.h"
#import "ClientDetailAndModifyController.h"
#import "LongRentalListController.h"
#import "LongerRentalAddController.h"
#import "VehicleListController.h"
#import "HeaderBannerCell.h"
#import "HomeFunctionCell.h"
#import "VehicleDetailController.h"
#import "VehicleAdditionController.h"
#import "RoleManagementController.h"
#import "RightsManagementController.h"

#import "ClientAddAPI.h"
#import "ClientDeleteAPI.h"
#import "ClientDetailAPI.h"
#import "UserAddAPI.h"
#import "UserDetailAPI.h"
#import "UserModifyAPI.h"
#import "UserDeleteAPI.h"
#import "UserListAPI.h"

#import "VehicleAdditionAPI.h"
#import "VehicleDetailAPI.h"
#import "VehicleListAPI.h"
#import "VehicleModifyAPI.h"
#import "VehicleDeleteAPI.h"

#import "OutRentAdditionAPI.h"
#import "OutRentDeleteAPI.h"
#import "OutRentModifyAPI.h"
#import "OutRentListAPI.h"
#import "OutRentDetailAPI.h"

#import "LongerRentalAdditionAPI.h"
#import "LongerRentalModifyAPI.h"
#import "LongerRentalListAPI.h"
#import "LongerRentalDetailAPI.h"

#import "FleetAddAPI.h"
#import "FleetListAPI.h"
#import "FleetDeleteAPI.h"
#import "FleetModifyAPI.h"
#import "FleetDetailAPI.h"


#import "MyOderListAPI.h"
#import "MyOrderListController.h"
#import "OrderDetailController.h"
#import "OrderAdditionController.h"
#import "CostReportController.h"


@interface HomeViewController ()<UITableViewDataSource,UITableViewDelegate,SelectFunctionCellDelegate>

@property (nonatomic,strong) UITableView *tableView;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.fd_prefersNavigationBarHidden = YES;
    [self.view addSubview:self.tableView];

    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.view);
    }];
}


#pragma mark - Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    //section头部高度
    return 0.00f;
}

//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
   
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = kAppBackgoundColor;
    return view;
}


 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     if (indexPath.section == 0) {
         return [HeaderBannerCell heightForCell];
     }else if(indexPath.section == 1){
         return [HomeFunctionCell heightForCell];
     }
     return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return   2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == 0){
        HeaderBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HeaderBannerCellIdentifier"];
        return cell;
    }else {
        HomeFunctionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeFunctionCellIdentifier"];
        cell.delegate = self;
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (void)testAPILink {
//      UserListAPI *api =  [[UserListAPI alloc] initWithPageSize:11 pageNum:3];
    MyOderListAPI *api =  [[MyOderListAPI alloc] initWithPageSize:1 pageNum:5 stateType:0];

    [api  startCedarRequestWithCompletionBlock:^(CedarBaseResponse * _Nullable response) {
        
    }];
    
}



- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [UIConfigure tableViewFromFactory];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 250;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kCellSpacingHeight)];
        [_tableView registerClass:[HeaderBannerCell class] forCellReuseIdentifier:@"HeaderBannerCellIdentifier"];
        [_tableView registerClass:[HomeFunctionCell class] forCellReuseIdentifier:@"HomeFunctionCellIdentifier"];
    }
    return _tableView;
}

#pragma mark - selectFunctionCellItemDelegate


- (void)selectFunctionCellItemIdex:(NSInteger)itemIdex {
    switch (itemIdex) {
        case 0:
            {
           OrderAdditionController *infoVC = [[OrderAdditionController  alloc] init];
            [self.navigationController pushToNewViewController:infoVC];
//                [self testAPILink];

            }
            break;
        case 1:
           {
               LongerRentalAddController *infoVC = [[LongerRentalAddController alloc] init];
               [self.navigationController pushToNewViewController:infoVC];
           }
           break;
        case 2:
            {
                ClientDetailAndModifyController *infoVC = [[ClientDetailAndModifyController alloc] init];
                [self.navigationController pushToNewViewController:infoVC];
            }
            break;
            
        default:
            break;
    }
 
}





@end
